home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0023_Delete a file QUICK.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  48 lines

  1. {
  2. JASON GROOMS
  3.  
  4. | Can anyone give me some code for a procedure to delete a file? I
  5. | cannot use the DOS EXEC procedure, due to memory conflicts, but I can
  6. | call on interrupts.
  7.  
  8. Here is a routine to add to your toolbox which will delete a file
  9. through DOS.
  10. }
  11.  
  12. function DeleteFile(FN : PathStr) : Boolean;
  13. var
  14.   Regs : Registers;
  15. begin
  16.   FN := FN + #0;          { Add NUL chr for DOS }
  17.   Regs.AH := $41;
  18.   Regs.DX := Ofs(FN) + 1; { Add 1 to bypass length byte }
  19.   Regs.DS := Seg(FN);
  20.   MsDos(Regs);
  21.   DeleteFile := NOT (Regs.Flags AND $0 = $0)
  22. end;
  23.  
  24. { Here is another routine to rename a file through DOS. }
  25.  
  26. function RenameFile(ON, NN : PathStr) : Boolean;
  27. var
  28.   Regs : Registers;
  29. begin
  30.   ON := ON + #0;       { Add NUL chr for DOS }
  31.   NN := NN + #0;       { Add NUL chr for DOS }
  32.   Regs.AH := $56;
  33.   Regs.DX := Ofs(ON) + 1; { Add 1 to bypass length byte }
  34.   Regs.DS := Seg(ON);
  35.   Regs.DI := Ofs(NN) + 1; { Add 1 to bypass length byte }
  36.   Regs.ES := Seg(NN);
  37.   MsDos(Regs);
  38.   RenameFile := NOT (Regs.Flags AND $0 = $0)
  39. end;
  40.  
  41. {
  42. These two routines require the Dos unit.
  43.  
  44.   **  Be warned that the delete file routine does not confirm the
  45.       delete, meaning it WILL delete the file if it exists so use
  46.       with care.
  47.  
  48. }